package com.heima.juc.n4;

import com.heima.juc.n2.Sleeper;
import lombok.extern.slf4j.Slf4j;

/**
 * @author : leimingchao
 * @date Date : 2022年02月11日 20:26
 */
@Slf4j(topic = "c.TestMultiLock2")
public class TestMultiLock2 {

    public static void main(String[] args) {

        BigRoom2 bigRoom2 = new BigRoom2();

        new Thread(() -> {
            bigRoom2.study();
        },"小南").start();


        new Thread(() -> {
            bigRoom2.sleep();
        },"小女").start();
    }
}


@Slf4j(topic = "c.BigRoom")
class BigRoom2 {

    private final Object studyRoom = new Object();

    private final Object bedRoom = new Object();

    public void sleep() {
        synchronized (bedRoom) {
            log.debug("sleeping 2 小时");
            Sleeper.sleep(2);
        }
    }

    public void study() {
        synchronized (studyRoom) {
            log.debug("study 1 小时");
            Sleeper.sleep(1);
        }
    }

}
